using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Net;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;

namespace TamTam.SharePoint.SolutionManagement.Services {

    /// <summary>
    /// Webservice to enable deployment of sharepoint solutions through msbuild.
    /// </summary>
    [WebService(Namespace = "http://services.sharepoint.local/", Name = "MsBuildDeployment", Description = "Webservice that enables the MsBuildTask \"SharePointSolutionDeploymentTask\" to deploy a sharepoint solution remotely.")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class MsBuildDeployment : System.Web.Services.WebService  {

        /// <summary>
        /// default empty constructor
        /// </summary>
        public MsBuildDeployment()
            : base() {
        }

        /// <summary>
        /// Method that actually is called by the MsBuild task <c>SharePointSolutionDeploymentTask</c>.
        /// </summary>
        /// <param name="solutionname">name of the solution ( filename inclus .wsp !!)</param>
        /// <param name="filedata">the binairy contents of the file</param>
        /// <returns>true if succesfull</returns>
        [WebMethod]
        public bool DeploySolution(
            string solutionname, 
            byte[] filedata,
            MsBuildTasks.Deployment deploymentType) {

            bool result = false;
            try {
                SolutionHandler.Deploy(solutionname, filedata, deploymentType);
                result = true;
            }
            catch(Exception exc) {
                Diagnostics.Logging.LogMessage(
                    "SolutionManagement",
                    "DeploySolution",
                    exc.Message);
            }
            return result;
        }
    }
}